<?php
$kuname="jipu";
$table="jipu_item";
$root=preg_replace("/^(.*(yunshop|shante)).*$/Uisx","\\1",getcwd());
include("{$root}/myzhuaqu.php");
if($_REQUEST['item_id']==""){
    if(preg_match("/https?\:\/\/shop\.shante\.me\/Item\/detail\/id\/([0-9]+)\.html/Uisx",$_POST["s_url"],$nn)){
        $_REQUEST['item_id']=$nn[1];
    }elseif(preg_match("/https?\:\/\/shop\.shante\.me\/Shop\/Item\/edit\/id\/([0-9]+)\.html/Uisx",$_POST["s_url"],$nn)){
        $_REQUEST['item_id']=$nn[1];
    }
}
$sql="select * from jipu.jipu_item where id={$_REQUEST['item_id']}";//.
$rs=getrow($sql);
$_SERVER['DOCUMENT_ROOT']="D:\\wwwroot\\www\\shop";
$_SERVER['DOCUMENT_ROOT']="http://shop.shante.me";
$mainImage=getone("select path from jipu.jipu_picture where id='{$rs['thumb']}'");
$rs["mainImage"]=$_SERVER['DOCUMENT_ROOT'].str_replace("/","/",$mainImage);
$images0=query("select path from jipu.jipu_picture where id in ({$rs['images']})");
$images=array();
for($i=0;$i<count($images0);$i++){
    $images[]=$_SERVER['DOCUMENT_ROOT'].str_replace("\\","/",$images0[$i]["path"]);
}
$data=$rs;
$url=$_SESSION["url"]=preg_replace("/(\?|\#).*$/","",$_POST["s_url"]);
$r=query("SELECT id,jspath,`type`,`value`,url  FROM jipu.`jipu_collect` WHERE url='{$_POST['url']}'");//
$content="";
for ($i = 0; $i < count($r); $i++) {
    $o=$r[$i]['jspath'];
    if($r[$i]['type']=="text"||$r[$i]['type']=="textarea") {
        $content .= $o . ".value='" . preg_replace("/$/m","",str_replace("'","\'",html($rs[$r[$i]['value']]))) . "'\n";
    }
    if($r[$i]['type']=="click") {
        $content .= $o . ".click()\n";
    }
    if(substr($r[$i]['type'],0,2)=="v_") {
        $content .= template($r[$i]['type'],$data);
    }
}
$rs["shante_script"]=$content;
file_put_contents("click.js",$content);

$rs["images"]=$images;
echo json_encode($rs);
